<?php
class Admin_Form_CreateUser extends Custom_Form
{
        private $_user_id = '';

	function  __construct($userid = '') {
		$this->_user_id = $userid;
		parent::__construct(null);
	}
    
	public function init()
	{
        
        $translate = Zend_Registry::get('translate');
        $objcompany  = new User_Model_DbTable_CompanyRole();
        $companyroles = $objcompany->getAll();     
        
        $objpayment = new User_Model_DbTable_PaymentPlan();
        $paymentplan = $objpayment->getAll();
       
        
        $objmembership = new User_Model_DbTable_UserMembership();
        $membership = $objmembership->getAll();

        $this->setName("signup");
        $this->setMethod('post');

        $this->addElement('text', 'user_fullname', 
                                   array('label' => $translate->_('Name'),
                                         'required' => true,
                                         'filters'=> array('StringTrim'),
                                       
            'validators' => array(array('StringLength', false, array(0, 50)))
        ));

        $this->addElement('text', 'companyname', 
                           array('label' => $translate->_('Company Name'), 
                                 'required' => true,
                                 'filters'=> array('StringTrim')));

        $this->addElement('select', 'company_role_id', array(
                                    'class' => 'styled',
                                    'required' => 'true',
                                    'label' => $translate->_('Your role at company'),
                                    'multiOptions' => array('' => 'select'),
                                     
        ));

            

        $this->addElement('text', 'user_email', 
                        array('label' => $translate->_('Email Address'), 
                              'required' => 'true',
                              'filters'=> array('StringTrim'),
                              'validators' => array(
                               array('EmailAddress'),
                              array('Db_NoRecordExists',false,array('table'=>'viz_user','field'=>'user_email','exclude'=>array('field'=>'id','value'=>$this->_user_id))))));
        
//        $this->addElement('text', 'username', 
//                            array('label' => $translate->_('Username'), 
//                                  'required' => 'true',
//                                  'filters'=> array('StringTrim'),
//                                 'validators' => array(
//                               
//                              array('Db_NoRecordExists',false,array('table'=>'viz_user','field'=>'username','exclude'=>array('field'=>'id','value'=>$this->_user_id))))
//                                  ));
        
        
        
        $this->addElement('password', 'password',
                           array('label' => $translate->_('Password'),
                                
                                 'filters'=> array('StringTrim')));
        
        $this->addElement('select', 'status', 
                            array('label' => $translate->_('User Status'), 
                                  'required' => 'true',
                                  'filters'=> array('StringTrim'),
                                  'multioptions'=>array('TRIAL'=>'TRIAL','REGULAR'=>'REGULAR', 'DISABLED'=>'DISABLED', 'EXPIRED'=>'EXPIRED','DELETED'=>'DELETED') , 
                                   ));
        
        $this->addElement('select', 'payment_plan_id', 
                            array('label' => $translate->_('Payment Plan'), 
                                  'required' => 'true',
                                   'multioptions'=>array(''=>'select'), 
                                   ));
        $this->addElement('text', 'expire_on', 
                            array('label' => $translate->_('Expire on'), 
                                  'required' => 'true',
                                   ));

        $this->addElement('text', 'user_phone',
                                   array('label' => $translate->_('Phone Number'),
                                         'required' => 'true',
                                         'filters'=> array('StringTrim')));

        $this->addElement('submit', 'submit', 
                                    array('ignore' => true,
                                         'required' => false,
                                          'lable'=>$translate->_('Register'),
                                        ));

        $element = $this->getElement('submit');
        $element->removeDecorator('label');
        
            foreach ($companyroles as $roles) 
            {
                $this->company_role_id->addMultiOption($roles['company_role_id'], $roles['name']);
            }
            
            foreach ($paymentplan as $payment) 
            {
                $this->payment_plan_id->addMultiOption($payment['payment_plan_id'], $payment['name']);
            }
        
       
        
        $this->user_fullname->addErrorMessage($translate->_('ERR_SIGNUP_FULLNAME'));
        $this->companyname->addErrorMessage($translate->_('ERR_SIGNUP_LASTNAME'));
        $this->company_role_id->addErrorMessage($translate->_('ERR_SIGNUP_COMPANYROLE'));
        $this->user_email->addErrorMessage($translate->_('ERR_SIGNUP_EMAIL'));
//        $this->username->addErrorMessage($translate->_('ERR_SIGNUP_USERNAME'));
        $this->password->addErrorMessage($translate->_('ERR_SIGNUP_PASSWORD'));
  
        $this->user_phone->addErrorMessage($translate->_('ERR_SIGNUP_PHONE'));
		
	}
}
?>